#include <iostream>

struct Person {
	std::string name;
	int age;
};

void set_person(Person & person);
void display_person(const Person & person);
Person & update_person(Person & person, std::string name, int age);

const Person & clone(Person & person);

int main(int argc, const char * argv[])
{
	using namespace std;
	Person p;
	set_person(p);
	display_person(p);
	p = update_person(p, "yyy", 24);
	display_person(p);
	
	Person q;
	set_person(q);
	update_person(p, "yyy", 24) = q;//返回的引用指向 p ,等价于 p = q;
	display_person(p);
	
	const Person & jelly = clone(p);
	
	cout << "p address is " << &p << endl;
	cout << "jelly address is "  << &jelly << endl;
	delete &jelly;
	
	return 0;
}

void set_person(Person & person)
{
	person.name = "xxx";
	person.age = 23;
}


void display_person(const Person & person)
{
	using std::cout;
	cout << "The person name is " << person.name << std::endl;
	cout << "age is " << person.age << std::endl;
}

Person & update_person(Person & person, std::string name, int age)
{
	person.name = name;
	person.age = age;
	return person;
}

const Person & clone(Person & person)
{
	Person *p = new Person;
	* p = person;
	return *p;
}